<!--
 * @Author: xuzehan 123@qq.com
 * @Date: 2023-04-11 14:14:15
 * @LastEditors: xuzehan 935351619@qq.com
 * @LastEditTime: 2024-05-07 15:53:33
 * @FilePath: \ant-design-vue-jeecg-master\src\views\taskManagement\taskAllocation.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="taskAllocation">
    <a-collapse v-model="activeKey">
      <a-collapse-panel key="1" header="资源分配">
        <h2>
          下行速率切换
          <!-- <a-button @click="handleConfig" type="primary" style="margin-left: 10px">配置详情</a-button> -->
        </h2>
        <a-form-model :model="form" :label-col="labelCol1" :wrapper-col="wrapperCol1">
          <a-row>
            <!-- <a-col :span="8">
              <a-form-model-item label="指控车">
                <a-input v-model="form.ncvName" read-only></a-input>
              </a-form-model-item>
            </a-col>-->
            <a-col :span="12">
              <a-form-model-item label="当前受干扰导弹速率">
                <a-input read-only v-model="form.rate"></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-card title style="width: 100%">
            <a-form-model v-bind="layout" :model="formInline" style="margin-top:30px">
              <a-row>
                <a-col :span="24">
                  <a-form-model-item
                    label="建议切换的新速率"
                    :label-col="{ span: 3 }"
                    :wrapper-col="{ span: 18 }"
                  >
                    <!-- <span class="rateSpan">档位1: 3ksps</span>
                    <span class="rateSpan">档位2: 12ksps</span>
                    <span class="rateSpan">档位3: 24ksps</span>
                    <span class="rateSpan">档位4: 48ksps</span>
                    <span class="rateSpan">档位5: 96ksps</span>-->
                    <a-radio-group v-model="form.newRate" @change="onChange">

                      <a-radio-button
                        v-for="item in rateList"
                        :key="item.value"
                        :value=item.value
                        class="rateSpan"
                        >
                        {{item.label}}
                      </a-radio-button>


                    </a-radio-group>
                  </a-form-model-item>
                </a-col>
                <a-col :span="24">
                  <a-form-model-item
                    label="目指信息的传输周期"
                    :label-col="{ span: 3 }"
                    :wrapper-col="{ span: 18 }"
                  >
                  <a-input-number
                    placeholder="范围1-32,单位s"
                    :precision="0"
                    :max="32"
                    :formatter="value => `${value}s`"
                    :parser="value => value.replace('s', '')"
                    :min="1"
                    v-model="form.transmissionCycle">
                </a-input-number>

                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24" :style="{ textAlign: 'right',marginRight:'30px' }">
                  <a-button type="primary" style="margin-left: 10px" @click="handleSend">发送</a-button>
                </a-col>
              </a-row>
            </a-form-model>
          </a-card>
        </a-form-model>
      </a-collapse-panel>
      <!-- <a-collapse-panel key="2" header="控制指令发送及响应"></a-collapse-panel> -->
    </a-collapse>
    <creat-instruct ref="creatInstruct" />
    <configModal ref="configModal" />
    <a-modal :visible="visible" width="55%" title="资源分配申请表" @cancel="handleOk" @ok="handleOk">
      <template slot="footer">
        <a-button key="submit" type="primary" @click="handleOk">退出</a-button>
      </template>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columnsSQB"
        :dataSource="dataSourceSQB"
        :pagination="ipagination"
        class="j-table-force-nowrap"
      >
        <span slot="action" slot-scope="text, record">
          <a-button @click="handleOk1(record)" type="primary">进入配置</a-button>
        </span>
      </a-table>
    </a-modal>
    <a-modal title :visible="visibleConfirm" @ok="handleOkConfirm" @cancel="handleCancelConfirm">
      确认是否切换以下导弹上行链路频点号 ?
      {导弹1 2 3}
    </a-modal>
  </div>
</template>

<script>
import { processDefineKey } from '@/api/processDefineKey'
import CascaderSelect from './modules/Cascader.vue'
import creatInstruct from './modules/createInstruct'
import { getAction, httpAction } from '@/api/manage.js'
import configModal from './modules/confidModal.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
//  <!-- 资源池 -->
import pool1 from './modules/resourcePool1.vue'
import { Turns, sum, hex2int } from '@/utils/util.js'
import { convert_ZDZA430 } from '@/utils/YaoCeUtil'
import { getByParamCode } from '@/api/YaoCeApi'
import { Select } from 'ant-design-vue'
export default {
  mixins: [JeecgListMixin],
  components: { creatInstruct, pool1, CascaderSelect, configModal },
  data() {
    return {
      data: {},
      visibleConfirm: false,
      visible: false,
      readOnly: true,
      rateList:[
        {label:'档位1: 3ksps',value:"0000"},
        {label:'档位2: 12ksps',value:"0001"},
        {label:'档位3: 24ksps',value:"0002"},
        {label:'档位4: 48ksps',value:"0003"},
        {label:'档位5: 96ksps',value:"0004"},
      ],
      columnsSQB: [
        {
          title: '指挥车名称',
          dataIndex: 'ncvName',
          key: 'ncvName',
        },
        {
          title: '导弹总数',
          dataIndex: 'applyMissileTotal',
          key: 'applyMissileTotal',
        },
        {
          title: '信道号总数（个）',
          dataIndex: 'applyDigitalFilterTotal',
          key: 'applyDigitalFilterTotal',
        },
        {
          title: '操作',
          key: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      layout: {
        labelCol: { span: 4 },
        wrapperCol: { span: 14 },
      },
      formInline: { localOscillator: '', cfp: '' },
      dataSourceSQB: [],
      text: `world.`,
      poolData: [],
      tabActiveKey: '1',
      activeKey: ['1', '2'],
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      labelCol1: { span: 8 },
      wrapperCol1: { span: 16 },
      form: { rate: "3ksps" },
      fightForm: { startDate: undefined },
      formBall: {},
      props: { multiple: true },
      url: {
        downFrequencySwitchDecision: "/antiInterfere/nmcAntiInterfereDownInfo/downFrequencySwitchDecision",
        sendConfig: "commandVehicle/nmcCommandVehicle/getCommandVehicleMissileAllocInfo",
        queryInfo: '/commandVehicle/nmcCommandVehicle/getCommandVehicleMissileAllocInfo',
        getModalList: '/digitalFilter/nmcDigitalFilterApplyInfo/list',
        getLatestPackageGridValue: '/grid/nmcPackageGridValue/getLatestPackageGridValue',
        sendPackage: '/channel/nmcChannelInfo/sendPackage',
        getNmcPackageGridValueByCode: '/grid/nmcPackageGridValue/code',
        nmcPackageGridList: '/grid/nmcPackageGrid/list',
        getCurrentDayRunningFightDemandDownRate:'/antiInterfere/nmcAntiInterfereDownInfo/getCurrentDayRunningFightDemandDownRate',
        addnmcPackageGridValue: '/grid/nmcPackageGridValue/add', //{"packageGridValue":"22AA","Values":["22","aa"],"packageGridId":"1663806762680139777"}
      },


      rules: {
        localOscillator: [{ required: true, message: '请选择', trigger: 'change,blur' }],
        cfp: [{ required: false, message: '请选择', trigger: 'change' }],
      },
    }
  },
  watch: {
    activeKey(key) {
      console.log(key)
    },
  },
  created() {
    this.loadData()
    this.getModalList()//获取要要配置的列表数据
  },
  methods: {

    getModalList() {
      getAction(this.url.getModalList, { pageSize: -1 }).then(res => {
        if (res.success) {
          if (res.result.records && res.result.records.length) { this.dataSourceSQB = res.result.records }
          else {
            this.dataSourceSQB = []
          }
        } else {
          this.$message.error(res.message)
        }

      })
     /* getAction(this.url.getCurrentDayRunningFightDemandDownRate).then(res=>{
        if(res.success){
          console.log(res);
          this.form.rate= this.rateList.find(i=>i.value==res.result).label
        }else {
          this.$message.error(res.message)
        }

      })*/

      getByParamCode({"paramCode": "ZDZA430"}).then(res => {
        if (res.success) {
          this.form.rate = convert_ZDZA430(res.result.paramOriginalValue);
        } else {
          this.$message.error(res.message)
        }
      });
    },
    getLatestPackageGridValue() {
      const that = this
      let obj = { gridCode: '2-可控接收机本振频点切换指令', packageCode: '2星弹上行链路接收机频率配置1', processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfOneHandleImplKey }
      getAction(this.url.getLatestPackageGridValue, obj).then((res) => {
        let a = res.result.packageGridValue
        this.formInline.localOscillator = a.slice(-1)
        this.changeLocalOscillator(a.slice(-1))

      })
      let obj1 = { gridCode: '2-滤波器选通指令', packageCode: '2星弹上行链路接收机频率配置1', processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfOneHandleImplKey }
      getAction(this.url.getLatestPackageGridValue, obj1).then((res) => {
        let b = res.result.packageGridValue
        let result = Turns(b, 2).slice(0, -2).split('').reverse()
        result.forEach((i, index) => {
          if (i == 1) {
            this.changeCheckS(that.ZPLBQList.find((item, idx) => idx == index), 1)
          }
        })
      })

      let obj2 = { gridCode: '3-滤波器选通指令', packageCode: '3星弹上行链路接收机频率配置2', processDefineKey: processDefineKey.SatelliteBombUpReceiverFreConfTwoHandleImplKey }
      getAction(this.url.getLatestPackageGridValue, obj2).then((res) => {
        let a = res.result.packageGridValue
        let result = this.Turns(a, 2).split('').reverse()
        that.SZLBQList.forEach((i) => {
          i.check = false
        })
        result.forEach((i, index) => {
          if (i == 1) {
            that.SZLBQList.find((item, idx) => idx == index).check = true
            // this.changeCheckSZLPQ(that.SZLBQList.find((item, idx) => idx == index).id)
          }
        })
      })
    },
    loadData() { },
    handleOkConfirm() {
      httpAction(this.url.sendConfig, this.data, 'post').then(res => {
        if (res.code == 200) {
          that.$message.success('发包成功！')
          this.visible = true
          this.visibleConfirm = false
          this.getModalList()
        } else {
          that.$message.error('发包失败！')
        }
      })

    },
    handleCancelConfirm() {
      this.visibleConfirm = false
    },
    handleOk() {
      this.$router.back()
    },
    handleOk1(record) {
      this.visible = false
      this.form = record
      // this.getLatestPackageGridValue()//获取最新值
      getAction(this.url.queryInfo).then(res => {
        let result = res.result
        if (result.nmcCommandVehicleVoList.length > 0) {
          //有指控车配置过中频滤波器和本振（则不可修改）中频滤波器和本振
          this.readOnly = true
          this.setBzValue(result.localFrequencyPoint.packageGridValue)
          this.setZpValue(result.intermediateFrequencyFilter.packageGridValue)
          this.setSzValue(result.frequencyFilterOpenInfo.packageGridValue, result)
          return
        } else {
          this.readOnly = false
        }
      })

    },
    handleSend() {
      if(!this.form.newRate){
        this.$message.error('请选择需要切换的新速率')
        return
      }if(!this.form.transmissionCycle){
        this.$message.error('请选择输入目指信息的传输周期')
        return
      }
      httpAction(this.url.downFrequencySwitchDecision, { speedRange: this.form.newRate,transmissionCycle:this.form.transmissionCycle }, 'post').then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          // this.visible = true
          // this.getModalList()
        } else {
          this.$message.error(res.message)
        }
      })



    },

    handleConfig() {
      this.$refs.configModal.showModal({}, 'ball')
    },


    onChange(e) {
      console.log(`checked = ${e.target.value}`);
    },
    handleCreatInstruct() {
      //指令一键生成
      this.$refs.creatInstruct.showModal(this.fightForm)
      console.log(this.fightForm)
    },
    filter(val) {
      if (this.checkList.indexOf(val) != -1) {
        return true
      } else {
        return false
      }
    },
  },
}
</script>
<style lang="less">
.ant-input-group-wrapper .ant-input-wrapper .ant-input-group-addon {
  color: #fff;
}
.taskAllocation {
  .ant-checkbox-group {
    // height: 300px;
    // line-height: 0.9;
    .ant-checkbox-wrapper {
      margin: 0;
    }
    .ant-col {
      width: auto;
      margin: 0;
    }
  }
}
.tabs .ant-row {
  width: 600px;
  .ant-checkbox-inner {
    width: 40px !important;
    height: 40px !important;
    text-align: center;
    &::after {
      width: 7px;
      height: 14px;
      left: 35%;
    }
  }
}
.ant-checkbox-inner {
  /* background-color: red !important; */
  border-color: #6e6e6e !important;
}
.rateSpan {
  margin: 5px 10px;
  border: 1px solid #17dcff;
  background: transparent;
  line-height: 50px;
  height: 50px;
  min-width: 120px;
  color: #fff;
  text-align: center;
}
</style>
